package com.lilili.ssh.user.action;

import java.sql.Date;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.lilili.ssh.base.BaseAction;
import com.lilili.ssh.user.model.User;
import com.lilili.ssh.user.service.UserManager;

public class UserAction extends BaseAction{
	@Autowired
	private UserManager userManager;
	User user=new User();
	public User getUser(){
		return user;
	}
	public void setUser(User user){
		this.user=user;
	}
	public String editUser(){
		String id=this.getRequest().getParameter("id");
		if(StringUtils.isNotEmpty(id)){
			user=userManager.getUser(id);
		}else{
			user.setRegDate(new Date(System.currentTimeMillis()));
		}
		return this.Result("editUser.jsp");
	}
	public String addUser(){
		userManager.saveUser(user);
		this.getRequest().setAttribute("result","数据保存成功！");
		return SUCCESS;
	}
	public String delUser() {
        HttpServletRequest request = this.getRequest();
        String idStr = request.getParameter("idStr");
        if (StringUtils.isNotEmpty(idStr)) {
            String [] ids=idStr.split(",");
            for(String s:ids){
            	userManager.removeUser(s);
            }
        }
        return SUCCESS;
    }
}
